package cn.tedu.m5;


import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


@Component
public class Consumer {
    //启动一个消费者，从列队接收消息，并传递给这个方法处理
    //消费者自动启动，不用手动开启

    //#{} : spring expression language - SPEL 可以直接访问spring容器中的对象
    //${} : OGNL
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "#{rndQueue.name}",declare = "false"),
            exchange = @Exchange(name = "topic_logs",declare = "false"),
            key = {"*.b.*"}))
    public void receive1(String msg){
        System.out.println("消费者1 收到：" + msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue,
            exchange = @Exchange(name = "topic_logs",declare = "false"),
            key = {"a.#","*.b.*","*.*.c"}))
    public void receive2(String msg){
        System.out.println("消费者2 收到：" + msg);
    }



}
